﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Objects;

namespace medder
{
    public partial class Welcome : Form
    {
        MedBaseEntities med = new MedBaseEntities();
        public static ObjectSet<User> users;

        public Welcome()
        {
            users = med.Users;
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Sign fm = new Sign();
            fm.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string login = TBLogin.Text;
            string password = TBPassword.Text;
            if (users.Where(x => (x.Login == login) && (x.Password == password)).Count() == 0)
                Info1.Text = "Неверно введены логин или пароль";
            else
            {
                User user = users.Where(x => (x.Login == login) && (x.Password == password)).FirstOrDefault();
                if (user.IsActive == false)
                    Info1.Text = "Учетная запись не активирована";
                else
                {
                    int type = user.TypeId;

                    switch (type)
                    {
                        case (int)TypeEnum.Doctor:
                            MainFormDoctor fm1 = new MainFormDoctor(user);
                            fm1.ShowDialog();
                            break;
                        case (int)TypeEnum.Registrator:
                            MainFormRegistrator fm2 = new MainFormRegistrator(user);
                            fm2.ShowDialog();
                            break;
                        case (int)TypeEnum.Patient:
                            MainFormPatient fm3 = new MainFormPatient(user);
                            fm3.ShowDialog();
                            break;

                    }
                }
            }

        }
    }
}
